package com.chookss.view;

import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.chookss.R;

import static android.view.animation.Animation.INFINITE;


/**
 * 加载……
 * <p>
 * 使用方法：
 * <p>
 * LoadingDialog dialog = new LoadingDialog(OcrActivity.this);
 * dialog.setCanceledOnTouchOutside(false); //显示
 * dialog.show();
 * <p>
 * dialog.dismiss();//取消
 */
public class LoadingDialog extends Dialog {

    private ImageView iv;
    private static ObjectAnimator rotation;

    public LoadingDialog(Context context) {
        super(context, R.style.loadinganimdialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loading_dialog_lay);
        iv = findViewById(R.id.loading_dialog_iv);
            rotation = ObjectAnimator.ofFloat(iv, "rotation", 0f, 360f);
        rotation.setDuration(2000).setRepeatCount(INFINITE);
        rotation.setInterpolator(new LinearInterpolator());
        rotation.start();

    }

    @Override
    public void onDetachedFromWindow() {
        if (null != iv) iv.clearAnimation();
        super.onDetachedFromWindow();
    }
}
